package com.itheima.health.util;

import java.util.Calendar;
import java.util.Date;

public class DateUtils{
    static Date date = new Date();
    //获取本周第一天
    static Calendar calendar = Calendar.getInstance() ;
    public static String getDay() {
        String day = String.format("%tF", date);
    return day;
    }


    public static String getThisWeekMonday() {

        //设置每周第一天是周一（防止每周第一天是周日）
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        //日历切换到周一
        calendar.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
        //获取周一日期的格式化输出字符串
        String firstDayOfTheWeek = String.format("%tF", calendar);
        return firstDayOfTheWeek;
    }


    public static String getFirstDayThisMonth() {
        //获取这个月的第一天和最后一天
        calendar.set(Calendar.DATE, 1) ;
        String firstDayOfTheMonth = String.format("%tF",calendar);
        calendar.set(Calendar.DATE,calendar.getActualMaximum(Calendar.DATE));
        String LastDayOfTheMonth = String.format("%tF",calendar);
        return firstDayOfTheMonth;
    }
}
